package physics.MovementControl;

import physics.GameObject;

import common.Math3D;
import common.Point3D;


public class JumperMovementController extends AbstractMovementController {
	

	public JumperMovementController(GameObject object) {
		super(object);
		hasMomentum = false;
		movementFriction = 0.05;
		movementLimit = 0.1;
		rotationLimit = 0.01;
		rotationFriction = 0.05;
	}	

	@Override
	protected void doMoveMomentum() {
		//Position3D position = object.getPosition();
		Point3D face = object.getFace();
		Point3D up = object.getUp();
		Point3D left = object.getLeft();
		
		super.doMoveMomentum();
		if (object.getPlanet().surfaceDistance(object) < 0.00001){
			object.getPlanet().pinpointToPlanet(object);
			Point3D toback = Math3D.subPoint(object.getCenter(), lastPosition.getCenter());
			object.getPlanet().pinpointToPlanet(object);

		}
		object.getPlanet().calculateFacingVectors(object);
		
		movementMomentum.rotateAgainst(left, up, face);
		movementMomentum.rotateWith(
				object.getLeft(),
				object.getUp(),
				object.getFace());
		
	}

	@Override
	protected void doRotationMomentum() {
		super.doRotationMomentum();
	}

	@Override
	
	protected void updateMomentum() {
		if (inTheAir()){
			Point3D gravity = Math3D.subPoint(object.getPlanet().getCenter(),
					object.getCenter());
			gravity.normalize(object.getPlanet().getGravity());
			movementMomentum.add(gravity);
			doRotationFriction();
		
		}else{
			super.updateMomentum();
		}

	}

	@Override
	protected void limitMovement() {
		double veticalstr = Math3D.getDotProduct(object.getUp(),
				movementMomentum);
		movementMomentum.sub(Math3D.scalePoint(object.getUp(), veticalstr));
		super.limitMovement();
		movementMomentum.add(Math3D.scalePoint(object.getUp(), veticalstr));

	}
	
	
	
	
	
	
}
